/**
 * Created by wang on 2017/2/28.
 */
$(function(){
	var myChart;
	var report = new myReport();
	report.daily_gaugechart(_pm);
	var span = $($('.daily-month1 ul li')[0]).children("div").children("span");
	$(span).css("display","block");
	$(span).parent().addClass("daily-active");
	onSwitch();
	createZChart(_xdateWeek,_ydataWeek);

/**
 * Created by wang on 2017/2/28.
 * 描述：函数
 */
//切换月份
 function onSwitch(){
	 var option = {
	    	    title: {
	    	        text: '',
	    	        left: 'left',
	    	        textStyle:{fontSize:16,fontWeight:'normal'}
	    	    },
	    	    tooltip: {
	    	        trigger: 'item',
	    	        formatter: '{a} <br/>{b} : {c}'
	    	    },
	    	    legend: {
	    	        left: 'left',
	    	        data: ['2的指数', '3的指数']
	    	    },
	    	    grid:{y2:30,y:30,x:10,x2:10},
	    	    xAxis: {
	    	        type: 'category',
	    	        name: 'x',
	    	        axisTick:false,
	    	        splitLine: {show: false},
	    	        data: ""
	    	    },
	    	    yAxis: {
	    	        name: '步数',
	    	        axisLine:false,
	    	        axisLabel:false,
	    	        axisTick:false,
	    	        splitLine:{
	                    show:true,
	                    interval:0
	                },
	    	    },
	    	    series: [{
	    	    	type: 'line',
	    	    	symbol:'circle',
	    	        symbolSize:8,
	    	        itemStyle :{
	    	              normal:{
	    	                  color:"#12b7f5"
	    	               }
	    	           },
	    	        lineStyle:{
	    	                normal:{
	    	                    color:"#12b7f5",
	    	                    width:'2'
	    	                }
	    	            },
					data:""
	    	    }]
	    	};
	$('.daily-month1 ul li div').click(function(){
		var _this = $(this);
		$('.daily-month1 ul li div span').hide();
		$('.daily-month1 ul li div').removeClass("daily-active");
		_this.children("span").css("display","block");
		_this.addClass("daily-active");
		if(_this.hasClass("week")){
			option.xAxis.data = _xdateWeek;
			option.series[0].data = _ydataWeek;
			myChart.setOption(option,true);
		}else if(_this.hasClass("month")){
			option.xAxis.data = _xdataMoth;
			option.series[0].data = _xdataMoth;
			myChart.setOption(option,true);
		}else if(_this.hasClass("year")){
			option.xAxis.data = _xdataYear;
			option.series[0].data = _xdataYear;
			myChart.setOption(option,true);
		}
	});
}
 
 function createZChart(x,y){
	    myChart = echarts.init(document.getElementById('echart'));
	    var xdata = x ;  //x轴时间戳  日期
	    var ydata = y ;
	    option = {
	    	    title: {
	    	        text: '',
	    	        left: 'left',
	    	        textStyle:{fontSize:16,fontWeight:'normal'}
	    	    },
	    	    tooltip: {
	    	        trigger: 'item',
	    	        formatter: '{a} <br/>{b} : {c}'
	    	    },
	    	    legend: {
	    	        left: 'left',
	    	        data: ['2的指数', '3的指数']
	    	    },
	    	    grid:{y2:30,y:30,x:10,x2:10},
	    	    xAxis: {
	    	        type: 'category',
	    	        name: 'x',
	    	        axisTick:false,
	    	        splitLine: {show: false},
	    	        data: xdata
	    	    },
	    	    yAxis: {
	    	        name: '步数',
	    	        axisLine:false,
	    	        axisLabel:false,
	    	        axisTick:false,
	    	        splitLine:{
	                    show:true,
	                    interval:0
	                },
	    	    },
	    	    series: [{
	    	    	type: 'line',
	    	    	symbol:'circle',
	    	        symbolSize:8,
	    	        itemStyle :{
	    	              normal:{
	    	                  color:"#12b7f5"
	    	               }
	    	           },
	    	        lineStyle:{
	    	                normal:{
	    	                    color:"#12b7f5",
	    	                    width:'2'
	    	                }
	    	            },
					data:ydata
	    	    }]
	    	};
	    myChart.setOption(option);
	}
});

